home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_Menu.c
-
- Contains: Menu handling routines.
-
- Written by: David H Nelson
-
- Copyright © 1993-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <9> 5/19/95 SJF Fix the about box to use CARequestModalFocus
- <5> 4/23/95 RB OD Menu overhaul
- <4> 1/23/95 RB Added support for the "View In Window" menu item.
- <3> 2/15/95 RB Added support for the "Insert…" menu item
- <2> 1/23/95 SJF Added support for CALib.
- <1> 11/20/93 DHN Created.
- */
-
- #ifdef USE_CALIB
- #include "CALib.h"
- #include "CAS_CAUtil.h"
- #endif
-
- #include "CAS_Globals.h"
-
- #include "CAS_Menu.h"
- #include "CAS_MenuItems.h"
- #include "CAS_Misc.h"
- #include "CAS_App.h"
- #include "CAS_Doc.h"
- #include "CAS_Event.h"
- #include "CAS_Win.h"
-
-
- //----------------------------------------------------------------------
- // local prototypes
-
- #if defined(__cplusplus)
- extern "C"
- {
- #endif
-
- static Boolean Menu_LoadMenubar(
- short mbarResID,
- Boolean drawIt );
- static pascal Boolean aboutFilter(
- DialogPtr theDialog,
- EventRecord *theEvent,
- short *itemHit );
- static void Menu_DoAboutBox( void );
- static void Menu_HandleAppleMenu(
- short menuItem,
- WindowPtr theWindow );
- static void Menu_HandleFileMenu(
- short menuItem,
- WindowPtr theWindow );
- static void Menu_HandleEditMenu(
- short menuItem,
- WindowPtr theWindow );
-
- #ifdef USE_CALIB
- static void Menu_HandleCALibMenu(
- short menuItem,
- WindowPtr theWindow );
- #endif
-
-
- #if defined(__cplusplus)
- }
- #endif
-
-
- //---------------------------------------------------------------------------
-
- void Menu_SetUpMenus( void )
- {
- MenuHandle targetMenuH;
- short i;
-
- /* $$$$$ need proper OD menus (Document/Edit) here */
- /* File-Quit == Document-Close */
-
- // If a MBAR rsrc kMenubar_standard doesn't exist, build it manually
-
- if (!Menu_LoadMenubar( kMenubar_standard, false ))
- {
- for (i=kAppleMenu; i<=kToolMenu; i++)
- {
- targetMenuH = GetMenu( i );
- if (targetMenuH != nil)
- {
- InsertMenu( targetMenuH, 0 );
- if (i == kAppleMenu)
- AppendResMenu( targetMenuH, 'DRVR' );
- }
-
- }
- }
-
- // $$$$$ don’t do this, because it inserts the Tools menu for the 2nd time!!!
- // App_SetUpMenus();
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- OSErr theErr;
-
- // Share the base menu configuration with CALib/OpenDoc
- CASetBaseMenuBar( GetMenuBar() );
- if (theErr = CAError())
- ; // handle the error
-
- // Now add in the tool menu to the tool bar, it was removed from the MBAR
- // resource in the OD resource files
-
- App_SetUpMenus();
-
- CARegisterCommand( kCACommandAppleMenu, kAppleMenu, 0 );
- CARegisterCommand( kCACommandAbout, kAppleMenu, kAboutItem );
-
- CARegisterCommand( kCACommandOpen, kFileMenu, kOpenSelectionItem );
- CARegisterCommand( kCACommandClose, kFileMenu, kCloseItem );
-
- CARegisterCommand( kCACommandInsert, kFileMenu, kInsertItem );
-
- CARegisterCommand( kCACommandUndo, kEditMenu, kUndoItem);
- CARegisterCommand( kCACommandRedo, kEditMenu, kRedoItem);
- CARegisterCommand( kCACommandCut, kEditMenu, kCutItem);
- CARegisterCommand( kCACommandCopy, kEditMenu, kCopyItem);
- CARegisterCommand( kCACommandPaste, kEditMenu, kPasteItem);
- CARegisterCommand( kCACommandPasteAs, kEditMenu, kPasteAsItem);
- CARegisterCommand( kCACommandClear, kEditMenu, kClearItem);
- CARegisterCommand( kCACommandSelectAll, kEditMenu, kSelectAllItem);
- CARegisterCommand( kCACommandGetPartInfo, kEditMenu, kPartInfoItem);
- CARegisterCommand( kCACommandPreferences, kEditMenu, kPreferencesItem);
- CARegisterCommand( kCACommandViewAsWin, kEditMenu, kViewInWindowItem);
- }
- #endif
-
- DrawMenuBar();
-
- gAppMenuBar = GetMenuBar();
-
- }
-
- //---------------------------------------------------------------------------
- // load and optionally redraw a new menu bar
-
- static Boolean Menu_LoadMenubar(
- short mbarResID,
- Boolean drawIt )
- {
- Handle menuBarHandle = NULL;
- MenuHandle menuHandle = NULL;
- Boolean didIt = false;
-
- menuBarHandle = GetNewMBar( mbarResID );
-
- if (menuBarHandle)
- {
- SetMenuBar( menuBarHandle );
- menuHandle = GetMenuHandle( kAppleMenu );
- if (menuHandle != NULL)
- AppendResMenu( menuHandle, 'DRVR' );
- didIt = true;
- }
-
- if (drawIt && (menuBarHandle != NULL))
- DrawMenuBar();
-
- return didIt;
- }
-
-
- //---------------------------------------------------------------------------
- // filter for about box. handles update events. returns true for mouseDown or
- // keyDown and false for all other events.
-
- static pascal Boolean aboutFilter(
- DialogPtr theDialog,
- EventRecord *theEvent,
- short *itemHit )
- {
- switch (theEvent->what)
- {
- case updateEvt:
- // try to handle the update; assume we did not handle it.
- Event_HandleUpdateEvent( theEvent );
- break;
-
- case activateEvt:
- // try to handle the update; assume we did not handle it.
- Event_HandleActivateEvent( theEvent );
- break;
-
- case mouseDown:
- case keyDown:
- // a click or a keystroke should release the dialog
- *itemHit = 1;
- return true; // we handled the event.
-
- default:
- // for any other event, fall through.
- break;
- }
-
- // we filter out all other events.
- return false;
- }
-
- //---------------------------------------------------------------------------
- // Display the about box
- static void Menu_DoAboutBox( void )
- {
- GrafPtr savedPort;
- DialogPtr theDialog;
- short iItemHit;
- ModalFilterUPP aboutFilterUPP;
- WindowPtr frontWindow;
-
- GetPort( &savedPort );
- App_ForceActivateFrontWindow( false );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- frontWindow = CAGetFrontDocWindow();
- if (!CARequestModalFocus( frontWindow))
- {
- // DisposeDialog( theDialog );
- return;
- }
- }
- #endif
- theDialog = GetNewDialog( kAboutBoxID, 0L, nil /* INFRONT*/ );
-
- if (theDialog == nil)
- return;
-
-
- SetPort( (GrafPtr)theDialog );
- SelectWindow( (WindowPtr)theDialog );
-
- aboutFilterUPP = NewModalFilterProc( aboutFilter );
-
- do
- {
- ModalDialog( aboutFilterUPP, &iItemHit );
- }
- while (iItemHit != 1);
-
- #ifdef USE_CALIB
- if (gCALibExists)
- CARelinquishModalFocus( frontWindow );
- #endif
-
- DisposeRoutineDescriptor( aboutFilterUPP );
- DisposeDialog( theDialog );
-
- App_ForceActivateFrontWindow( true );
- SetPort( savedPort );
- }
-
- //---------------------------------------------------------------------------
- // Menu_AdjustMenus -
-
- void Menu_AdjustMenus(
- WindowPtr theWindow )
- {
- MenuHandle fileMenuH;
- Boolean isAppWindow;
-
- fileMenuH = GetMenuHandle( kFileMenu );
- if (fileMenuH != nil)
- {
- isAppWindow = Win_IsAppWindow( theWindow );
-
- // adjust the close, save, saveAs, page setup, and print menu items.
- mhSetMenuItem(
- isAppWindow || Win_IsDAWindow( theWindow ),
- fileMenuH, kCloseItem );
- mhSetMenuItem( isAppWindow, fileMenuH, kSaveItem );
- mhSetMenuItem( isAppWindow, fileMenuH, kSaveAsItem );
- mhSetMenuItem( isAppWindow, fileMenuH, kPageSetUpItem );
- mhSetMenuItem( isAppWindow, fileMenuH, kPrintItem );
- }
-
- // give the app a chance to adjust any menus.
- App_AdjustMenus( theWindow );
-
- }
-
-
- //---------------------------------------------------------------------------
-
- void Menu_HandleMenu(
- long mSelect,
- WindowPtr theWindow )
- {
- short menuID, menuItem;
-
- menuID = HiWord( mSelect );
- menuItem = LoWord( mSelect );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- // CADispatchMenuEvent manufactures an event record if one isn't provided
- if (CADispatchMenuEvent( NULL, mSelect ))
- {
- return;
- }
-
- }
- #endif
-
- switch (menuID)
- {
- case kAppleMenu:
- Menu_HandleAppleMenu( menuItem, theWindow );
- break;
-
- case kFileMenu:
- Menu_HandleFileMenu( menuItem, theWindow );
- break;
-
- case kEditMenu:
- Menu_HandleEditMenu( menuItem, theWindow );
- break;
-
-
- default:
- App_HandleMenu( mSelect, theWindow );
- break;
- }
-
- HiliteMenu( 0 );
-
- }
-
- //---------------------------------------------------------------------------
- // Handle the Apple menu items here.
-
- static void Menu_HandleAppleMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- Str255 name;
-
- switch (menuItem)
- {
- case kAboutItem: // is it the about item.
- Menu_DoAboutBox();
- break;
-
- default: // It must be a DA
- GetMenuItemText( GetMenuHandle( kAppleMenu ), menuItem, name );
- OpenDeskAcc( name );
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // Handle the standard File menu items here.
-
- static void Menu_HandleFileMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- switch (menuItem)
- {
- case kNewItem:
- App_NewMenu();
- break;
-
- case kOpenItem:
- App_OpenMenu();
- break;
-
- case kCloseItem:
- App_CloseMenu( theWindow );
- break;
-
- case kSaveItem:
- App_SaveMenu( theWindow );
- break;
-
- case kSaveAsItem:
- App_SaveAsMenu( theWindow );
- break;
-
- case kPageSetUpItem:
- App_PageSetUpMenu( theWindow );
- break;
-
- case kPrintItem:
- App_PrintMenu( theWindow );
- break;
-
- case kQuitItem:
- App_QuitMenu();
- break;
-
- #ifdef USE_CALIB
- case kInsertItem:
- CAUtil_InsertMenu( theWindow );
- break;
-
- case kOpenSelectionItem:
- CAUtil_OpenSelectionMenu( theWindow );
- break;
- #endif
-
- default:
- App_HandleFileMenu( menuItem, theWindow );
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // Handle standard Edit menu items here.
-
- static void Menu_HandleEditMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- DocPtr theDoc;
-
- if (Win_IsAppWindow( theWindow ))
- {
- // get the theDoc
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- switch (menuItem)
- {
- case kUndoItem:
- //Doc_UndoMenu( theDoc );
- break;
-
- case kCutItem:
- Doc_CutMenu( theDoc );
- break;
-
- case kCopyItem:
- Doc_CopyMenu( theDoc, false );
- break;
-
- case kPasteItem:
- Doc_PasteMenu( theDoc );
- break;
-
- case kClearItem:
- Doc_ClearMenu( theDoc );
- break;
-
- case kSelectAllItem:
- Doc_SelectAllMenu( theDoc );
- break;
-
- #ifdef USE_CALIB
- case kPartInfoItem:
- CAUtil_PartInfoMenu( theDoc );
- break;
- #endif
- default:
- App_HandleEditMenu( menuItem, theWindow );
- break;
- }
- }
- else // it's not a document window
- {
- switch (menuItem)
- {
- case kUndoItem:
- case kCutItem:
- case kCopyItem:
- case kPasteItem:
- SystemEdit( menuItem - 1 );
- break;
-
- default:
- break;
- }
- }
- }
-
-
- //---------------------------------------------------------------------------
- #ifdef USE_CALIB
-
- static void Menu_HandleCALibMenu(
- short menuItem,
- WindowPtr theWindow )
-
- {
- DocPtr theDoc;
-
- if (Win_IsAppWindow( theWindow ))
- {
- // get the theDoc
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- switch (menuItem)
- {
-
- case kSelectAllParts:
-
- break;
-
- default: break;
-
- }
-
- }
-
-
- }
- #endif
-